﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using TeamDev.JQuery.Internals;

public static class jqSelectionFiltersExtensions
{
  #region Selection Filters

  public static jqDetailedSelector animated(this jqSimpleSelector filter) { return filter + ":animated"; }
  public static jqDetailedSelector even(this jqSimpleSelector filter) { return filter + ":even"; }
  public static jqDetailedSelector odd(this jqSimpleSelector filter) { return filter + ":odd"; }
  public static jqDetailedSelector first(this jqSimpleSelector filter) { return filter + ":first"; }
  public static jqDetailedSelector eq(this jqSimpleSelector filter, int value) { return filter + string.Format(":eq({0})", value); }
  public static jqDetailedSelector gt(this jqSimpleSelector filter, double value) { return filter + string.Format(":gt({0})", value); }
  public static jqDetailedSelector lt(this jqSimpleSelector filter, double value) { return filter + string.Format(":lt({0})", value); }
  public static jqDetailedSelector header(this jqSimpleSelector filter) { return filter + ":header"; }
  public static jqDetailedSelector last(this jqSimpleSelector filter) { return filter + ":last"; }
  public static jqDetailedSelector not(this jqSimpleSelector filter, jqBasicSelector selector) { return filter + string.Format(":not({0})", selector.Filter); }

  #endregion

  #region Selection Childs

  public static jqDetailedSelector first_child(this jqSimpleSelector filter) { return filter + ":first-child"; }
  public static jqDetailedSelector last_child(this jqSimpleSelector filter) { return filter + ":last-child"; }

  public static jqDetailedSelector nth_child(this jqSimpleSelector filter, int index) { return filter + string.Format(":nth-child({0})", index); }
  public static jqDetailedSelector nth_child(this jqSimpleSelector filter, string formula) { return filter + string.Format(":nth-child({0})", formula); }
  public static jqDetailedSelector nth_child_even(this jqSimpleSelector filter) { return filter + ":nth-child(even)"; }
  public static jqDetailedSelector nth_child_odd(this jqSimpleSelector filter) { return filter + ":nth-child(odd)"; }

  public static jqDetailedSelector only_child(this jqSimpleSelector filter) { return filter + ":only-child"; }

  #endregion

  #region Selection Content

  public static jqDetailedSelector contains(this jqSimpleSelector filter, string value) { return filter + string.Format(":contains({0})", value); }
  public static jqDetailedSelector empty(this jqSimpleSelector filter) { return filter + ":empty"; }
  public static jqDetailedSelector has(this jqSimpleSelector filter, jqBasicSelector selector) { return filter + string.Format(":has({0})", selector.Filter); }
  public static jqDetailedSelector parent(this jqSimpleSelector filter) { return filter + ":parent"; }

  #endregion

  #region Attribute Selectors

  [Description("Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).")]
  public static jqDetailedSelector attr_contains_prefix(this jqSimpleSelector filter, string name, string value)
  { return filter + string.Format("[{0}|={1}]", name, value); }

  [Description("Selects elements that have the specified attribute with a value containing the a given substring")]
  public static jqDetailedSelector attr_contains(this jqSimpleSelector filter, string name, string value)
  { return filter + string.Format("[{0}*={1}]", name, value); }

  [Description("Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.")]
  public static jqDetailedSelector attr_contains_word(this jqSimpleSelector filter, string name, string value)
  { return filter + string.Format("[{0}~={1}]", name, value); }

  [Description("Selects elements that have the specified attribute with a value ending exactly with a given string")]
  public static jqDetailedSelector attr_ends_with(this jqSimpleSelector filter, string name, string value)
  { return filter + string.Format("[{0}$={1}]", name, value); }

  [Description("Selects elements that have the specified attribute with a value exactly equal to a certain value")]
  public static jqDetailedSelector attr_equals_to(this jqSimpleSelector filter, string name, string value)
  { return filter + string.Format("[{0}={1}]", name, value); }

  [Description("Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value")]
  public static jqDetailedSelector attr_not_equals_to(this jqSimpleSelector filter, string name, string value)
  { return filter + string.Format("[{0}!={1}]", name, value); }

  [Description("Selects elements that have the specified attribute with a value beginning exactly with a given string.")]
  public static jqDetailedSelector attr_starts_with(this jqSimpleSelector filter, string name, string value)
  { return filter + string.Format("[{0}^={1}]", name, value); }

  [Description("Selects elements that have the specified attribute, with any value. ")]
  public static jqDetailedSelector has_attribute(this jqSimpleSelector filter, string name)
  { return filter + string.Format("[{0}]", name); }

  #endregion
}
